package com.mazj.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyInterceptor2 implements HandlerInterceptor {
    /**
     * 在执行Handler之前执行，用于身份效验，权限认证
     *
     * @param httpServletRequest
     * @param httpServletResponse
     * @param o
     * @return 返回true表示放行，返回false拦截
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        System.out.println("进入preHandle2");
        return true;
    }

    /**
     * 在执行handler的过程中，返回ModelAndView之前执行
     * 如果想要向页面提供一些公共数据，或者一些公用的配置信息可以考虑使用这里的ModelAndView对象
     * @param httpServletRequest
     * @param httpServletResponse
     * @param o
     * @param modelAndView
     * @throws Exception
     */
    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        System.out.println("进入postHandle2");
    }

    /**
     * 在执行Handler之后执行
     * 日志，系统性能分析
     * @param httpServletRequest
     * @param httpServletResponse
     * @param o
     * @param e
     * @throws Exception
     */
    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
        System.out.println(httpServletRequest.getRequestURL());
        System.out.println("进入afterCompletion2");
    }
}
